import { wechatrequest } from './API/request'
import { getStorageSync } from '../crossplatform/apiservice/storage'

/**
 * 申请加入公司
 * */
export const operatorRequest = ({ companyId }) => {
  const userinfo = getStorageSync('userinfo') || {}
  return wechatrequest.postparams(`/orgOperator/apply/operator`, {
    data: {
      companyId,
      userId: userinfo.userId
    }
  })
}

/**
 * 删除被拒公司数据
 * */
export const operatorRejectRequest = ({ }) => {
  const userinfo = getStorageSync('userinfo') || {}
  return wechatrequest.postparams(`/orgOperator/clearUserOperationHistory`, {
    data: {
      userId: userinfo.userId
    }
  })
}

/**
 * 查询管理者信息
 * */
export const operatorMessageRequest = ({ companyId }) => {
  return wechatrequest.postparams(`/orgOperator/list/operator`, {
    data: {
      companyId
    }
  })
}

/**
 * 企业主页查询
 * */
export const companyInfoRequest = (data = {}) => {
  let companyId = data.companyId || getStorageSync('userinfo').companyId
  return wechatrequest.postform(`/orgCompany/getCompanyDetail`, {
    data: { companyId }
  })
}

/**
 * 解绑招聘者
 * */
export const releaseoperatorRequest = ({ userId, operatorId }) => {
  const userinfo = getStorageSync('userinfo') || {}
  return wechatrequest.postparams(`/orgOperator/release/operator`, {
    data: {
      companyId: userinfo.companyId,
      openId: userinfo.openId,
      userId,
      operatorId
    }
  })
}

/**
 * 转让管理员
 * */
export const updateoperatorRequest = ({ userId }) => {
  const userinfo = getStorageSync('userinfo') || {}
  return wechatrequest.postparams(`/orgOperator/update/operator`, {
    data: {
      companyId: userinfo.companyId,
      openId: userinfo.openId,
      userId
    }
  })
}

/**
 * 解绑招聘者
 * */
export const unbindCompanyRequest = () => {
  return wechatrequest.postparams(`@@/operator/unbindCompany`, {
    data: {}
  })
}
